package com.ayoka.parenting.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.ayoka.parenting.R;
import com.jincp.common.dialog.BaseDialogBuilder;
import com.jincp.common.dialog.BaseDialogFragment;


/**
 * =========================================================
 * @ProjectName:
 * @ClassName: LoadingDialogFragment
 * @Description:
 * @Author: jincp
 * @CreateDate: 2019/3/21 17:25
 * =========================================================
 */
public class LoadingDialogFragment extends BaseDialogFragment {

    private static LoadingDialogFragment newInstance(Builder builder) {
        LoadingDialogFragment dialog = new LoadingDialogFragment();
        Bundle bundle = getArgumentBundle(builder);
        bundle.putString("Message", builder.message);
        dialog.setArguments(bundle);
        return dialog;
    }

    @Override
    protected void convertView(@Nullable View container, BaseDialogFragment dialogFragment) {
        TextView loadMessage = (TextView) container.findViewById(R.id.load_msg);

        Bundle bundle = getArguments();
        if (bundle != null){
            String message = bundle.getString("Message");
            if (TextUtils.isEmpty(message)){
                message = getString(R.string.loading);
            }
            loadMessage.setText(message);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.layout_loading_dialog;
    }

    public static class Builder extends BaseDialogBuilder<Builder, LoadingDialogFragment> {

        private String message;

        public Builder setMessage(String message) {
            this.message = message;
            return this;
        }

        @Override
        public LoadingDialogFragment build() {
            return LoadingDialogFragment.newInstance(this);
        }
    }
}
